//
//  ZSENVTableViewController.m
//  ZhuShou
//
//  Created by Dejun Liu on 15/11/2.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSENVTableViewController.h"
#import "ZSNoneTableViewCell.h"
#import "ZSImageTableViewCell.h"

@interface ZSENVTableViewController ()

@property (nonatomic,strong) NSArray *list;

@end

@implementation ZSENVTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.list = @[@{
                      @"title":@"客厅",
                      @"value":@""
                      },
                  @{
                      @"title":@"厨房",
                      @"value":@""
                      },
                  @{
                      @"title":@"主卧",
                      @"value":@""
                      },
                  @{
                      @"title":@"次卧",
                      @"value":@""
                      }
                  ];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZSImageTableViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    
    
    //    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData:)];
    //    self.tableView.header = header;
    //
    //    MJRefreshAutoStateFooter *footer = [MJRefreshAutoStateFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestData:)];
    //    self.tableView.footer = footer;
    //
    //    [self.tableView.header beginRefreshing];
    [self br_addRightEditingItem];
}

- (void)br_editHandle:(UIBarButtonItem *)item
{
    [super br_editHandle:item];
    NSInteger tag = item.tag;
    if (tag) {
        [self br_addNewButton:YES btnTitle:@"添加场景"];
        [self.tableView setEditing:YES];
    }else
    {
        [self br_addNewButton:NO btnTitle:@"添加场景"];
        [self.tableView setEditing:NO];
    }
}

- (void)br_newButtonHandle:(UIButton *)button
{
    [self br_pushViewControllerWithClassName:@"ZSENVTableViewController"];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"Cell";
    ZSImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    NSDictionary *dic = [self.list objectAtIndex:indexPath.row];
    cell.nameLabel.text = [dic objectForKey:@"title"];
    cell.imageView.image = [UIImage imageNamed:@"icon_home"];
    
    return cell;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 44.0f;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark RequestData

- (void)requestData:(MJRefreshHeader *) commponent
{
    [self.tableView.header endRefreshing];
    [self.tableView.footer endRefreshing];
    [self.tableView.footer noticeNoMoreData];
}


@end
